Arrays

Arrays consist of one or more elements of the same data type such as int, double or float. They can be addressed with 32-bit indices with the data type int32 or uint32.

If an array is of the type int8[] or uint8[] and applied to a parameter or a channel in a step list, a string value can be entered, see Data Types - Strings.

Arrays can be created in the Type Editor, see Type Editor, and assigned to a signal in the Declaration Editor, see Declaration Editor.

Array definition in the Type Editor

It is possible to declare multidimensional arrays that consist of array or matrix elements.

Array basic operations

array := 2
// sets each value of the array to 2

array[0]
// access to the first element of the array by indexing with [], where the first index is zero

array[0] = 42;
// single values within an array can be replaced by indexing the array

array_1 = array_2;
// arrays can be copied into each other if both arrays have the same size and data type

array[-1]
// negative index addresses from end of array

array := max([1,2,3])
// sets the result value to 3

array := min([1,2,3])
// sets the result value to 1

Min/max values of an array

Since min() and max() have only one argument, the array must be one-dimensional.

Array slicing operations

The syntax is <start index>:<stop index>:<step size>.

If you want to slice an array, variables can be used instead of integers to refer to an index or a step size. If you use a variable for the <start index> or leave it out and also leave out the <stop index> and use a variable for the <step size>, you must insert a space between the two colons. So, TPT will not confuse it with the namespace syntax, which is <namespace>::<signal name>, see TPT Modeling Language - Namespaces.

array[start:end]
// from fixed start to fixed end

array[:end]
// from first array index to fixed end

array[start:]
// from fixed start to last array index

array[:]
// full array range

array[-3:-1]
// negative index addresses from end of array

array[0:myVar]
// usage of variables in range expressions

myCube[0:1][:][-1]
// arbitrary slices of multidimensional arrays, with myCube being a three-dimensional array

array_a[1:3] := array_b[4:6]
// expressions with array slices on left and right hand side

In the following an example with the array [0,1,2,3,4,5,6] is considered:

array[1:3]
// elements from index 1 to index 3; results in [1, 2, 3]

array[1:3]:=[2,3,4]
// sets the second, third, and fourth value to 2,3, and 4

array[2: :]
// elements from index 2; results in [2,3,4,5,6]

x = 2
array[x: :]
// elements from index 2; results in [2,3,4,5,6]

y = 2
array[: :y]
// sliced every 2nd step; results in [0,2,4,6]

z = 4
array[2: :z]
// elements from index 2, sliced every 4th step; results in [2, 6]

y = 2; z = 4
array[y: :z]
// elements from index 2, sliced every 4th step; results in [2, 6]

myCube[0:1][:][-1]
// arbitrary slices of multidimensional arrays, with myCube being a three-dimensional array

Array binary operations

+, -, *, /

[1,2,3,4]*3=[3,6,9,12]
// the multiplication with a skalar

Binary operations work element-by-element.

[1,2,3]*[4,5,6]=[4,10,18]
// the multiplication with an array; performed element-by-element; the dimension of the arrays must be the same

Binary operations in a step list

Array comparison operations

When using arrays in comparison operations (==, !=, <, <=, >, >=, =~=) the following applies:

Assigning scalar values

A single value assigned to an array can be a scalar value that applies to all elements of an array.

A scalar value that applies to all elements of an array

Indexing via constants

It is possible to reference to an array index via a constant to access an array element. The constant must be either of the data type uint32, uint16 , or uint8.

Array indexing via a constant

Iteration over all indices

Arrays consist of one or more elements identified by their indices. TPT supports the iteration over all indices of an array. For example, the array bar consists of the two elements bar[0] and bar[1]. When using the following Python syntax an iteration can be performed:

for elem in bar:

print elem.getName()

Iteration over the array "bar"

Array size access

When using :size the size or dimension of an array can be accessed in step lists.

The array size access in assessment scripts does not work by using ":size". Instead, you have to use Python, for example: AssessmentVar(t):=len(array_parameter). For more information, see Assessment Functions.

Arrays in TPT are addressed with 32-bit indices, that means the returned data type of :size used in step lists is always uint32. Make sure your signal type matches uint32. Otherwise, the signal value must be casted, see TPT Modeling Language - Type Cast.

Array size access in step lists